<!--
 * @Author: wangjian
 * 656876071@qq.com
 * @Date: 2024-09-04 18:12:59
 * @LastEditTime: 2024-09-05 10:42:37
 * @FilePath: src/views/sxln/member/TableDictCell.vue
 * @Description: 
 -->
<script setup lang="ts">
import {inject, onMounted, type Ref, ref, watch} from "vue";

const {value,code} = defineProps(["value","code"])

const dictText = ref("")

const dictCollection: Ref = inject('dictCollection', ref({}))
//如果是字典先加载完成，后渲染数据
onMounted(()=>{
  console.log("dictCollection",dictCollection)
  let dict = dictCollection.value[code]
  if(!dict)
    return
  for (let option of dict) {
    if(option.value == value){
      dictText.value = option.label
      break;
    }
  }
})
//如果数据已经渲染，后加载的字典数据
watch(dictCollection,()=>{
  console.log("dictCollection更新了",dictCollection)
  let dict = dictCollection.value[code]
  if(!dict)
    return
  for (let option of dict) {
    if(option.value == value){
      dictText.value = option.label
      break;
    }
  }
})

</script>

<template>
<span>{{ dictText}}</span>
</template>

<style scoped>

</style>